<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>订单报表</title>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/default/easyui.css"/>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/icon.css"/>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/demo.css"/>
	<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.min.js"></script>
	<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.easyui.min.js"></script>
	<script src="${pageContext.request.contextPath}/plugins/jQuery/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript">
		$(function(){
		    
		     $('#station').combobox({
				valueField:'station_id', //值字段
				textField:'station_name', //显示的字段
				url:'${pageContext.request.contextPath }/admin/station/findStationByKind/1',
				onLoadSuccess : function(data) {
		            $('#station').combobox("setValue",-1);
	        	}
	        });
		  
			loadTable();
			$('#dg').dialog('close');
		});
		
		function loadTable(){
			//设置时间  
			var curr_time = new Date();     
		   	var s = $("#start_time").textbox('getValue');
		   	var e = $("#end_time").textbox('getValue');
		   
		   if(s != null && s != '' && e !=null && e!='')
		   {
		       $("#start_time").textbox("setValue",s);
		 		$("#end_time").textbox("setValue",e);
		   }else{
		       $("#start_time").textbox("setValue",myformatter(curr_time));  
				 $("#end_time").textbox("setValue",myformatter(curr_time));
		   }

			$('#dg').datagrid({
			    remoteSort:false,
			    singleSelect:true,
		 		url:'${pageContext.request.contextPath }/goods/getGoodsInfolist',
		 		queryParams:{
		 			 station:$('#station').combobox("getValue"),
		 			 start_time:$("#start_time").textbox('getValue'),
		 			 end_time:$("#end_time").textbox('getValue')
		 		},
		 		showFooter: true,
	    		columns:[[
					{field:'goods_id',title:'商品编码',align:'center',width:200},
					{field:'goods_name',title:'商品名称',align:'center',width:150},
					{field:'goods_kind',title:'品种类型',align:'center',width:80},
					{field:'goods_packing',title:'商品包装',align:'center',width:80},
					{field:'sale_num',title:'合计数量',align:'center',sortable:true},
					{field:'weight',title:'合计重量/斤',align:'center',sortable:true},
					{field:'store_num',title:'预估库存',align:'center',formatter: function (value, row, index) {
						var str=""+value;
						if(value==null) value=0;
						var status=value-row.sale_num;
						if(status<=5){
							str="<span style='color:red;font-weight:bold;'>"+value+"</span>";
						}
						return str;
					}},
					{field:'original_price',title:'总金额/元',width:100,align:'center',sortable:true},
					{field:'un_price',title:'优惠金额/元',width:100,align:'center',sortable:true},
					{field:'sale_price',title:'实际金额/元',width:80,align:'center',sortable:true}
	 			]],
	 			/*
	 			rowStyler:function(index,row){    
			        if (row.goods_packing=='合计'){    
			          return 'background-color:pink;color:blue;font-weight:bold;';    
			        }    
		   		},    
	 			*/
				onLoadSuccess:function(data){
			       //添加“合计”列
			       /*
		            $('#dg').datagrid('appendRow', {
				                  goods_packing: '<span class="subtotal">合计</span>',
					              sale_num: '<span class="subtotal">' + compute("sale_num") + '</span>',
					              weight: '<span class="subtotal">' + compute("weight") + '</span>',
					              original_price: '<span class="subtotal">' + compute("original_price") + '</span>',
					              un_price: '<span class="subtotal">' + compute("un_price") + '</span>',
					              sale_price: '<span class="subtotal">' + compute("sale_price") + '</span>',
					              store_num: '<span class="subtotal">' + compute("store_num") + '</span>'
				   });
			       */
				}
			});
		}
		
		 //指定列求和
        function compute(colName) {
            var rows = $('#dg').datagrid('getRows');
            var total = 0;
            for (var i = 0; i < rows.length; i++) {
                total += parseFloat(rows[i][colName]);
            }
            return total;
        }
		
		function showImg(imgUrl){
			$('#dlg').dialog('open');
			var image=document.getElementById("stationImg");
			var src="${pageContext.request.contextPath }"+imgUrl;
			image.setAttribute("src",src );
		}

		// 打开一个新的选项卡，并制定选项卡的名称
		function show(url,name){
			parent.window.addTab(name,url);
		}
		
		function findData(){
			loadTable();
		}
		
		function myformatter(date){  
	      var y = date.getFullYear();  
	      var m = date.getMonth()+1;  
	      var d = date.getDate();  
	      return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);  
	   }  
	          
	function myparser(s){  
	    if (!s) return new Date();  
	    var ss = (s.split('-'));  
	    var y = parseInt(ss[0],10);  
	    var m = parseInt(ss[1],10);  
	    var d = parseInt(ss[2],10);  
	    if (!isNaN(y) && !isNaN(m) && !isNaN(d)){  
	        return new Date(y,m-1,d);  
	    } else {  
	        return new Date();  
	    }  
	}  

	</script>
	<style type="text/css">
		body{
		font-family:'微软雅黑';}
		.subtotal { font-weight: bold; }/*合计单元格样式*/
	</style>
  </head>
  
  <body>
    <table id="dg" title="订单报表" toolbar="#searchtool" loadMsg="正在查询..." style="width:90%;height:700px;"></table>
    <div id="searchtool" style="padding:5px;height:auto;">  
       <span style="margin:0px 12px;">站点:</span><input id="station" class="easyui-textbox" style="width:180px;height:26px"/> 
       <span style="margin:0px 12px;">下单时间:</span><input id="start_time" class="easyui-datebox" data-options="formatter:myformatter,parser:myparser" style="width:120px"> -- <input id="end_time" class="easyui-datebox" data-options="formatter:myformatter,parser:myparser" style="width:120px">
       <a href="javascript:findData()" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:100px;margin:0px 3px;">查询</a>
       <a href="javascript:findData()" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" style="width:100px;margin:0px 3px;">刷新</a>
    </div>
  </body>
</html>
